
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings; use Ada.Strings;

-- https://leetcode.com/problems/container-with-most-water/
procedure leet11_maxarea is 
    type vector is array (integer range<>) of integer;

    function min(i : integer; j : integer) return integer is
    begin
        if i > j then 
            return j;
        end if;
        return i;
    end min;

    function max(i : integer; j : integer) return integer is
    begin
        if i < j then
            return j;
        end if;
        return i;
    end max;
    
    function maxarea(v : vector) return integer is
        area_current : integer;
        area_max     : integer := 0;
        h    : integer;
        i    : integer := 1; -- iterations
        distance : integer := v'length - i;
    begin
        for int of v loop
            for int2 of reverse v loop
                if distance > 0 then
                    h := min(int, int2);
                    area_current := h * distance;
                    area_max := max(area_current, area_max);
                end if;
                distance := distance - 1;
            end loop;
            i := i + 1;
            distance := v'length - i;
        end loop;
        return area_max;
    end maxarea;

    procedure main is 
        result : integer;
        v  : vector := (1,8,6,2,5,4,8,3,7);
        v1 : vector := (1,1);
        v2 : vector := (4,3,2,1,4);
    begin 
        result := maxarea(v);
        put_line(integer'image(result));

        result := maxarea(v1);
        put_line(integer'image(result));

        result := maxarea(v2);
        put_line(integer'image(result));
        return;
    end main;

begin
    put_line("This is leetcode algorithm challenge #11 - Most Water (Area)");
    main;
    return;
end leet11_maxarea;
